package com.budwk.app.sqfwV2.service.educationalInstitution;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.budwk.app.sqfw.constants.SqfwFormSummaryConstants;
import com.budwk.app.sqfw.models.Sqfw_formSummary_new;
import com.budwk.app.sqfw.services.SqfwCompleteflowService;
import com.budwk.app.sqfwDoc.codeGenerator.pdfGenerate.AbstractCustomerPdfCreateField;
import com.budwk.app.sqfwDoc.codeGeneratorV2.fileParam.CompleteFlowBusinessParam;
import com.budwk.app.sqfwDoc.codeGeneratorV2.fileParam.CompleteFlowPdfParamForController;
import com.budwk.app.sqfwDoc.codeGeneratorV2.fileParam.PdfGenerateParam;
import com.budwk.app.sqfwDoc.codeGeneratorV2.generate.BasePdfGenerator;
import com.budwk.app.sqfwDoc.codeGeneratorV2.pdfService.CompleteFlowCommonPdfService;
import com.budwk.app.sqfwDoc.codeGeneratorV2.result.GeneratorPdfWordResult;
import com.budwk.app.sqfwV2.dto.EducationalInstitutionDTO;
import com.budwk.app.sqfwV2.dto.LandscapePatrolDTO;
import com.budwk.app.sqfwV2.enums.EducationalInstitutionEnums;
import com.budwk.app.sqfwV2.generator.educationalInstitution.EducationalInstitutionPdfGenerator;
import com.budwk.app.sqfwV2.generator.landscapePatrol.LandscapePatrolPdfGenerator;
import com.google.common.collect.Lists;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;

import java.util.List;

@IocBean
public class EducationalInstitutionPdfService extends CompleteFlowCommonPdfService {

    @Inject
    SqfwCompleteflowService sqfwCompleteflowService;

    @Override
    public void createPdfAndMsg(CompleteFlowPdfParamForController paramForController) {
        super.createPdfAndMsg(paramForController);
    }


    @Override
    public GeneratorPdfWordResult createPdfSync(CompleteFlowPdfParamForController paramForController) {
        return super.createPdfSync(paramForController);
    }

    /**
     * 获取用户自定义字段 代码生成器已经自动填充
     * 无需特殊修改
     *
     * @param paramData json字符串
     * @return 结果
     */
    @Override
    protected AbstractCustomerPdfCreateField getCustomerPdfField(String paramData) {
        return JSONObject.parseObject(paramData, EducationalInstitutionDTO.class);
    }

    /**
     * 允许用户自定义填充在创建pdf时所提供的数据
     *
     * @param pdfGenerateParam 创建pdf所提供的数据
     */
    @Override
    protected void customerPopularPdfGenerateParam(PdfGenerateParam pdfGenerateParam) {


    }

    /**
     * 在这里设置生成pdf的所有generator
     *
     * @param pdfGenerateParam 创建pdf的参数
     * @return 生成pdf的generator合集
     */
    @Override
    protected List<BasePdfGenerator> getPdfGenerator(PdfGenerateParam pdfGenerateParam) {
        List<BasePdfGenerator> generatorList = Lists.newArrayList();
        CompleteFlowBusinessParam businessParam = (CompleteFlowBusinessParam) pdfGenerateParam.getBusinessParam();
        Sqfw_formSummary_new formSummary = businessParam.getFormSummary();
        EducationalInstitutionDTO  landscapePatrolDTO = JSON.parseObject(formSummary.getParamData(), EducationalInstitutionDTO.class);
        generatorList.add(new EducationalInstitutionPdfGenerator(EducationalInstitutionEnums.getPdfTemplatName(landscapePatrolDTO.getInstitutionalCategory())));
        return generatorList;
    }

    /**
     * 用户自定义下载pdf文件的名称
     *
     * @param pdfGenerateParam 创建pdf所提供的参数
     * @return 结果
     */
    @Override
    protected String getDownloadFileName(PdfGenerateParam pdfGenerateParam) {
        CompleteFlowBusinessParam businessParam = (CompleteFlowBusinessParam) pdfGenerateParam.getBusinessParam();
        Sqfw_formSummary_new formSummary = businessParam.getFormSummary();
        EducationalInstitutionDTO educationalInstitutionDTO = JSON.parseObject(formSummary.getParamData(), EducationalInstitutionDTO.class);
        return StrUtil.format(EducationalInstitutionEnums.getFileName(educationalInstitutionDTO.getInstitutionalCategory()));
    }

    /**
     * 第五张表中的需要的类型，详情见 {@link SqfwFormSummaryConstants}
     *
     * @return 返回数据
     */
    @Override
    public String getSummaryType() {
        return SqfwFormSummaryConstants.inspection_of_non_academic_educational_institutions;
    }



}